home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / test / heap.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  106 lines

  1. /* Test class Heap
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Modification History:
  11.     
  12. $Log:    heap.c,v $
  13.  * Revision 3.0  90/05/20  00:29:12  kgorlen
  14.  * Release for 1st edition.
  15.  * 
  16. */
  17. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/heap.c,v 3.0 90/05/20 00:29:12 kgorlen Rel $";
  18.  
  19. #include "Heap.h"
  20. #include "Integer.h"
  21. #include "OrderedCltn.h"
  22. #include "Set.h"
  23. #include "Point.h"
  24.  
  25. const int test1[] = {100, 70, 76, 22, 101, 54, 60, 2, 5, 601};
  26. const int test2[] = {57, 36, 45, 59, 20, 14, 32, 18, 5, 28,
  27.     17, 30, 16, 65, 34, 27, 30, 31, 80, 8,
  28.     37, 39,    38, 45, 50, 15, 12, 13, 10, 25, 15};
  29.  
  30. main()
  31. {
  32.      cout << "Testing Heap" << endl;
  33.     OrderedCltn oc(10);
  34.     for (int i = 0; i < sizeof test1/sizeof(int); i++)
  35.         oc.add(*new Integer(test1[i]));
  36.     cout << oc << endl;
  37.  
  38.     cout << "Test asHeap function" << endl;
  39.     cout << "OrderedCltn as Heap:\n" << oc.asHeap() << endl;
  40.     Heap heap1 = oc.asHeap();
  41.  
  42.     Heap heap2(1);        // Check reSize function
  43.     for (i = (sizeof test1/sizeof(int))-1; i >=0; i--)
  44.         heap2.add(*new Integer(test1[i]));
  45.     cout << "Test isEqual function" << endl;
  46.     cout <<  (heap1.isEqual(heap2) ? "SUCCESS" : "FAILURE") << endl;
  47.     heap2.add(*new Integer(60));
  48.     cout <<  (heap1!=heap2 ? "SUCCESS" : "FAILURE") << endl;
  49.     heap2.removeFirst();
  50.     cout <<  (heap1==heap2 ? "FAILURE" : "SUCCESS") << endl;
  51.  
  52.     Point A(1,1);
  53.     Point B(1,2);
  54.     Point C(1,3);
  55.     Point D(1,3);
  56.     Heap b(16);
  57.     b.add(A);
  58.     b.add(B);
  59.     b.add(C);
  60.     b.add(D);
  61.     Heap c = b;
  62.     cout << "b = " << b << endl;
  63.     cout << "c = " << c << endl;
  64.     c.removeAll();
  65.     cout << "c = " << c << endl;
  66.     c = b;
  67.     cout << "c.removeId(D)->isSame(D): " << c.removeId(D)->isSame(D) << endl;
  68.     cout << "b.first(): " << *(b.first()) << endl;
  69.     cout << "b.last(): " << *(b.last()) << endl;
  70.     Point E(4,5);
  71.     b.add(E);
  72.     cout << "b = " << b << endl;
  73.     cout << "remove min from b " << *b.removeFirst() << endl;
  74.     cout << "remove max from b " << *b.removeLast() << endl;
  75.     Point F(3,2);
  76.     Point G(1,4);
  77.     Point H(5,6);
  78.     Point I(0,1);
  79.     Point J(9,8);
  80.     b.add(F);
  81.     b.add(G);
  82.     b.add(H);
  83.     b.add(I);
  84.     b.add(J);
  85.     b.add(I);
  86.     b.add(B);
  87.     b.add(A);
  88.     b.add(B);
  89.     cout << "b= " << b << endl; 
  90.     cout << "\noccurrencesOf((1,2)): " << b.occurrencesOf(B) << endl;
  91.     cout << "b.sort(): " << b.sort() << endl;
  92.     cout << "b.asSet(): " << (b.asSet()) << "\n" << endl;
  93.  
  94.     cout << "Testing remove(Object&)" << endl;
  95.     Heap aheap(15);
  96.     for (i = 0; i < sizeof test2/sizeof(int); i++)
  97.         aheap.add(*new Integer(test2[i]));
  98.     cout << aheap << '\n' << endl;
  99.     aheap.remove(*new Integer(10));
  100.     cout << aheap << '\n' << endl;
  101.     aheap.remove(*new Integer(80));    
  102.     cout << aheap << '\n' << endl;
  103.     aheap.remove(*new Integer(18));
  104.     cout << aheap << '\n' << endl;
  105. }
  106.